package com.asj.vivo.lock.activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.asj.R;

public class LockActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //配置UI
        ConfigLockUI();
    }

    /**
     * 配置锁机界面UI的方法
     * */
    public void ConfigLockUI(){
        EdgeToEdge.enable(this);

        setContentView(R.layout.lock_page);

        // 获取传递过来的Intent
        Intent intent = getIntent();
        // 从Intent中获取传递的参数
        String closeFlag = intent.getStringExtra("closeFlag");
        if(closeFlag != null && closeFlag.equals("true")){
            Toast.makeText(this, "已成功解除锁定", Toast.LENGTH_SHORT).show();
            this.finishAffinity();
        }

        String content = intent.getStringExtra("content");
        // 使用获取到的参数，例如设置TextView的文本
        TextView textView = findViewById(R.id.lock_content); // 假设这是锁机页面上的TextView
        textView.setText(content);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.lock_main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
    }

    @Override
    public void onBackPressed() {
        Intent intent = getIntent();
        // 从Intent中获取传递的参数
        String content = intent.getStringExtra("content");
        if(content != null && !content.isEmpty()){
            Toast.makeText(this, "设备已被锁定，请联系客服人员解锁", Toast.LENGTH_SHORT).show();
        }else{
            super.onBackPressed();
        }
    }

}
